import sys
import time

import cv2
import numpy as np
import dxcam
import imagehash
from PIL import Image
import ctypes


camera = None

def get_screen_shot():
    camera = dxcam.create()
    screenshot = camera.grab()

    pic = Image.fromarray(screenshot)
    hash = imagehash.phash(pic)
    print(hash)

    img = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)

    pic = Image.fromarray(img)
    hash = imagehash.phash(pic)
    print(hash)

    if img is None:
        print("获取截图失败")
        return
    return img

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False

if __name__ == '__main__':
    if is_admin():
        print("获取到管理员")
        time.sleep(4)
        pic = get_screen_shot()
        cv2.imshow("pic", pic)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
    else:
         if sys.version_info[0] == 3:
            print("没获取到")
            ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)


